package com.design.yjx.composite;

/**
 * @author yuanjianxin
 * @date 2017/8/28 10:28
 */
public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        AbstractDuckFactory factory = new CountingDuckFactory();
        main.simulate(factory);
    }

    public void simulate(AbstractDuckFactory factory) {
        Quackable mallard =factory.createMallardDuck();
        Quackable redHead = factory.createRedHeadDuck();
        Quackable rubber = factory.createRubberDuck();
        Quackable goose = new QuackCounter(new GooseAdapter(new Goose()));

        simulate(mallard);
        simulate(redHead);
        simulate(rubber);
        simulate(goose);

        System.out.println(QuackCounter.count());
    }

    public void simulate(Quackable quackable) {
        quackable.quack();
    }
}
